package com.it.demo.util;

import cn.hutool.json.JSONUtil;
import com.it.demo.entity.common.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class WebUtils {
    /**
     * 将字符串渲染到客户端
     *
     * @param response 渲染对象
     * @param result   待渲染的字符串
     * @return null
     */
    public static String response(HttpServletResponse response, Result result) {
        try {
            response.setStatus(200);
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(JSONUtil.toJsonStr(result));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
